// 存放的是最新路由规则数组
import { asyncRoutes } from '@/router'
import { constantRoutes } from '@/router'

const state = {
  // 响应式的
  routes: constantRoutes
}
const mutations = {
  setRoutes(state, otherRoutes) {
    // 每个人进来都应该是基于静态路由,新增一些动态路由,而不是累加push
    state.routes = [...constantRoutes, ...otherRoutes]
  }
}
const getters = {}
const actions = {
  // 封装一个过滤路由规则的action, 希望将来如果你想过滤路由规则,直接调用action
  // 过滤路由需要:1所有的动态路由  2menus
  filterRoutes(context, menus) {
    console.log(asyncRoutes, menus, 77777)
    // 判断条件:如果路由模块的默认页面路由规则name zai menus中存在,这个权限他有,路由规则的留下来
    const res = asyncRoutes.filter(item => menus.includes(item.children[0].name))
    console.log(res, 9999999)
    context.commit('setRoutes', res)
    return res
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  getters,
  actions
}
